package org.gitos.cloud.server.mq.logic;

import org.gitos.cloud.domain.device.Device;
import org.gitos.cloud.domain.device.Router;
import org.gitos.cloud.domain.mq.MqMsg;
import org.gitos.cloud.domain.tcp.Bucket;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Created by shizhengchu on 16/1/19.
 */
public class DefaultRecLogic implements Runnable {

	private static final Logger log = LoggerFactory
			.getLogger(DefaultRecLogic.class);

	private MqMsg msg;
	private Router router;

	public MqMsg getMsg() {
		return msg;
	}

	public void setMsg(MqMsg msg) {
		this.msg = msg;
	}

	public DefaultRecLogic(MqMsg msg, Router router) {
		this.msg = msg;
		this.router = router;
	}

	@Override
	public void run() {
		byte[] bytes = msg.getBucket().toFrame();
		Device device = new Device();
		device.setChannelId(msg.getChannelId());
		device.setNodeId(msg.getNodeId());
		device.setDeviceId(msg.getBucket().getDeviceId());
		router.registerDevice(device);
	}
}
